package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAnswerService;
import cn.wolfcode.trip.base.service.IQuestionService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("answer")
public class AnswerController {

    @Autowired
    private IAnswerService answerService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        PageInfo<Answer> result = answerService.queryForList(qo);
        model.addAttribute("pageInfo", result);
        return "qna/answerlist";
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        answerService.delete(id);
        return new JSONResult();
    }

    @RequestMapping("update")
    @ResponseBody
    public JSONResult update(Answer answer){
        Boolean golden = answer.getGolden();
        answer.setGolden(!golden);
        answerService.update(answer);
        return new JSONResult();
    }

}
